package panel.home.fastBtn
{
	import assists.HtmlText;
	import assists.SizeManager;
	import assists.TextFieldUtils;
	
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class FastBtnBase extends Sprite
	{
		protected var _bitmap:DisplayObject;
		protected var _nameTxt:TextField;
		protected var _onClickFunc:Function;
		private var _nameStr:String;
		protected var _txtBack:Shape;

		public function FastBtnBase()
		{
			super();
			init();
		}
		
		protected function init():void
		{
			
		}
		
		public function render(bitmap:DisplayObject,name:String):void
		{
			_bitmap = bitmap;
			this.addChild(bitmap);
			_nameTxt = new TextField();
			_nameTxt.autoSize = "left";
			_nameTxt.mouseEnabled = false;
			TextFieldUtils.setHtmlText(_nameTxt,HtmlText.format(name,0xffffff,12));
			_nameTxt.mouseEnabled = false;
			_txtBack = new Shape();
			_txtBack.graphics.beginFill(0,0.6);
			_txtBack.graphics.drawRoundRect(0,0,_nameTxt.width,_nameTxt.height,5,5);
			this.addChild(_txtBack);
			this.addChild(_nameTxt);
			scale();
			addEvent();
		}
		
		protected function addEvent():void
		{
			this.addEventListener(MouseEvent.CLICK,clickHanler);
		}
		
		protected function clickHanler(event:MouseEvent):void
		{
			if(_onClickFunc != null)
			{
				_onClickFunc(this);
			}
			
		}
		
		public function set clickFunc(value:Function):void
		{
			_onClickFunc = value;
		}
		
		protected function resize():void
		{
			_nameTxt.x = (_bitmap.width - _nameTxt.width) / 2;
			_nameTxt.y = SizeManager.donwGuideHeight;
			_txtBack.x = _nameTxt.x;
			_txtBack.y = _nameTxt.y;
		}
		
		public function clear():void
		{
			this.removeChild(_bitmap);
//			_bitmap.bitmapData.dispose();
			_bitmap = null;
			
			this.removeChild(_nameTxt);
			_nameTxt = null;
		}
		
		public function scale():void
		{
			_bitmap.scaleX = _bitmap.scaleY = SizeManager.fromeNumToscale(3,_bitmap.width);
			resize();
		}
		
		override public function get width():Number
		{
			return _bitmap.width;
		}
		
		override public function get height():Number
		{
			return _bitmap.height;
		}
		
	}
}